<!--#
layout("/layouts/platform.html"){
#-->
<!--后台观点管理页面-->
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <!--搜索框-->
        <div class="btn-group tool-button mt5">
            <el-input v-model="pageForm.searchKeyword" @keyup.enter.native="doSearch"
                      placeholder="用户名或昵称或者手机号码或观点单号" size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                    size="medium"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
        </div>
        <!--搜索条件-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.matchType" placeholder="赛事类型"
                       size="medium" style="width: 120px">
                <el-option
                        v-for="item in matchTypeData"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val">
                </el-option>
            </el-select>
        </div>
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.status" placeholder="状态"
                       size="medium" style="width: 120px">
                <el-option
                        v-for="item in statusData"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val">
                </el-option>
            </el-select>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                size="small"
                header-align="center"
                style="width: 100%">
            <el-table-column
                    label="观点单号"
                    prop="no"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="headPicture"
                    label="头像"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template scope="scope">
                    <p v-if="scope.row.headPicture && scope.row.headPicture.substring(0, 1) == '/'">
                        <img :src="scope.row.headPicture" style="width: 60px;height: 60px">
                    </p>
                    <p v-else-if="scope.row.headPicture && scope.row.headPicture.substring(0, 1) != '/'">
                        <img :src="'/' + scope.row.headPicture" style="width: 60px;height: 60px">
                    </p>
                    <p v-else>
                        暂无数据
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                    label="昵称"
                    prop="nickName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="league"
                    label="联赛名"
                    header-align="center"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="赛事类型"
                    prop="matchType"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template slot-scope="scope">
                    <span>{{getMatchTypeName(scope.row.matchType)}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="title"
                    label="标题"
                    header-align="center"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="内容"
                    prop="content"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="观点状态"
                    prop="result"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.result === -1">未中奖</span>
                    <span v-else-if="scope.row.result === 0">待结算</span>
                    <span v-else>中奖</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="不中退款"
                    prop="refundable"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.refundable">是</span>
                    <span v-else>否</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="审核状态"
                    prop="status"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template slot-scope="scope">
                    <span>{{getStatusName(scope.row.status)}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    label="审核意见"
                    prop="remark"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="出售数量"
                    prop="saleNum"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--创建时间-->
            <el-table-column
                    prop="ctAt"
                    label="创建时间"
                    header-align="center"
                    align="center"
                    width="120px">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>
            <!--操作下拉菜单-->
            <el-table-column
                    label="操作"
                    width="120"
                    align="center">
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand">
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
<!--                            <el-dropdown-item divided :command="{type:'detail',id:scope.row.id}">-->
<!--                                详情-->
<!--                            </el-dropdown-item>-->
                            <el-dropdown-item v-if="scope.row.status == 'WAIT'" :command="{type:'audit', id:scope.row.id}">
                                审核
                            </el-dropdown-item>
                            <el-dropdown-item v-if="scope.row.saleNum == 0" divided :command="{type:'delete', id:scope.row.id, name:scope.row.nickName}">
                                删除
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <!--分页容器-->
    <el-row class="el-pagination-container">
        <div class="pull-left offscreen-right mt5">
            <el-pagination
                    @size-change="pageSizeChange"
                    @current-change="pageNumberChange"
                    :current-page="pageForm.pageNumber"
                    :page-sizes="[10, 20, 30, 50]"
                    :page-size="pageForm.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageForm.totalCount">
            </el-pagination>
        </div>
    </el-row>
    <el-dialog
            title="审核"
            :visible.sync="auditDialog"
            width="40%">
        <el-form :model="auditData" ref="auditForm" size="small" label-width="80px">
            <el-form-item prop="remark" label="审核意见">
                <el-input maxlength="100" placeholder="审核意见"
                          v-model="auditData.remark"
                          auto-complete="off" tabindex="1" type="text"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="audit('PASS')" type="success">通过</el-button>
            <el-button @click="audit('FAIL')" type="danger">不通过</el-button>
            <el-button @click="auditDialog = false" type="info">取 消</el-button>
        </span>
    </el-dialog>
</div>
<script src="${base!}/assets/platform/js/sha256.js"></script>
<script>
    function getParams(key) {
        var result = {};
        var paramStr = encodeURI(window.document.location.search);
        if (paramStr) {
            paramStr = paramStr.substring(1);
            var param4Map = paramStr.split('&');
            for (var p = 0; p < param4Map.length; p++) {
                result[param4Map[p].split('=')[0]] = unescape(param4Map[p].split('=')[1]);
            }
        }
        let resultElement = result[key];
        return resultElement===undefined?"":resultElement;
    }
    vue = new Vue({
        el: "#app",
        data: function () {
            return {
                pickerOptions: {
                    disabledDate: function (time) {
                        var threeMonths = moment().add(-3, 'months').valueOf();
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
                            || time.getTime() < threeMonths;
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                searchDate: [],
                auditDialog: false,
                tableData: [],
                selectData: [],
                matchTypeData: [],
                statusData: [],
                auditData: {},
                pageForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    matchType: "",
                    searchKeyword: getParams("no"),
                    searchDate: "",
                },
                formData: {
                    nickname: "",
                    phone: "",
                    disabled: false,
                }
            }
        },
        methods: {
            getMatchTypeName:function(val){
                for (let matchTypeDataKey in this.matchTypeData) {
                    if (this.matchTypeData[matchTypeDataKey].val === val) {
                        return this.matchTypeData[matchTypeDataKey].name;
                    }
                }
            },
            getStatusName:function(val){
                for (let statusDataKey in this.statusData) {
                    if (this.statusData[statusDataKey].val === val) {
                        return this.statusData[statusDataKey].name;
                    }
                }
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/view/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            matchTypeLoad: function () {
                var self = this;
                // 分类数据请求接口
                $.post(base + "/platform/user/view/matchTypeList", function (data) {
                    if (data.code === 0) {
                        self.matchTypeData = data.data;
                        self.matchTypeData.unshift({
                            val: '',
                            name: '全部类型'
                        })
                    }
                }, "json");
            },
            statusLoad: function () {
                var self = this;
                // 分类数据请求接口
                $.post(base + "/platform/user/view/statusList", function (data) {
                    if (data.code === 0) {
                        self.statusData = data.data;
                        self.statusData.unshift({
                            val: '',
                            name: '全部状态'
                        })
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                //审核
                if('audit' === command.type){
                    this.auditData = {
                        id: command.id,
                        remark:"",
                        status:"",
                    };
                    this.auditDialog = true;
                }
                // 删除按钮
                if ("delete" === command.type) {
                    self.$confirm('确定要删除用户<' + command.name + '>的观点么', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" === a) {//确认后再执行
                                $.post(base + "/platform/user/view/del/" + command.id, function (data) {
                                    if (data.code === 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            audit: function (val) {
                var self = this;
                self.auditData.status = val;
                $.post(base + "/platform/user/view/audit", self.auditData, function (data) {
                    if (data.code === 0) {
                        self.$message({
                            message: data.msg,
                            type: 'success'
                        });
                        self.auditDialog = false;
                        self.pageData();
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            }
        },
        created: function () {
            this.matchTypeLoad();
            this.statusLoad();
            this.pageData();
        }
    });
</script>

<!--#
}
#-->